package org.jeecg.modules.zonglzp.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.zonglzp.entity.Customer;
import org.jeecg.modules.zonglzp.entity.ExcelEntity;
import org.jeecg.modules.zonglzp.mapper.CustomerMapper;
import org.jeecg.modules.zonglzp.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CustomerServiceImpl implements CustomerService {


    @Autowired
    CustomerMapper mapper;

    //查询我的客户列表
    @Override
    public IPage<Customer> getCustomerlist(Page<Customer> page, String userid, String customerCode, String customerName) {
        return mapper.getCustomerlist(page, userid, customerCode, customerName);
    }

    @Override
    public Customer getyuangongbycode(String customerCode) {
        return mapper.getyuangongbycode(customerCode);
    }


    //查询未量体员工
    @Override
    public IPage<Customer> getweiliangtiyuangong(Page<Customer> page, String departId) {
        return mapper.getweiliangtiyuangong(page, departId);
    }


    //设置花名册
    @Override
    public void sethmc(Customer title, String departId) {
        mapper.sethmc(title, departId, new Date());
    }

    //先把老的花名册全部删了
    @Override
    public void deletedeparthmc(String departId2) {
        mapper.deletedeparthmc(departId2);
    }

    @Override
    public List<Customer> gettitles(String departId) {
        return mapper.gettitles(departId);
    }


    //查询花名册内容
    @Override
    public IPage<Customer> gethmclist(Page<Customer> page, String departId) {
        String title1 = null;
        String title2 = null;
        String title3 = null;
//        for (int i=0;i<titles.size();i++){
//            if(titles.get(i).getTitlenumber()==1){
//                title1=titles.get(i).getTitle();
//            }
//            if(titles.get(i).getTitlenumber()==2){
//                title2=titles.get(i).getTitle();
//            }
//            if(titles.get(i).getTitlenumber()==3){
//                title3=titles.get(i).getTitle();
//            }
//        }
        return mapper.gethmclist(page, departId);
    }


    //删除花名册中的员工
    @Override
    public int deleteCustomer(int id) {
        return mapper.deleteCustomer(id);
    }

    //编辑花名册中的员工
    @Override
    public int updateCustomer(Customer customer) {
        return mapper.updateCustomer(customer);
    }

    //设置花名册中下载模板 模板中的数据
    @Override
    public List<ExcelEntity> getmobandata() {
        return mapper.getmobandata();
    }


    @Override
    public void importhmc(ExcelEntity excelEntity, String departId, int parentId) {
        excelEntity.setDepartId(departId);
        excelEntity.setParentId(parentId);
        excelEntity.setCreateTime(new Date());
//        System.out.println("打印看一看啦"+excelEntity.toString());
        //先查询这个code的用户之前是否已经存在
        String customercode=mapper.getcustomercodebycode(excelEntity.getCustomerCode(),parentId);
        if(customercode==null)
        mapper.importhmc(excelEntity);
    }


    //清空部门
    @Override
    public int cleardepart(String departId) {
        return mapper.cleardepart(departId);
    }

    //获取人数
    @Override
    public int getsexNumber(String departId, int i) {
        return mapper.getsexNumber(departId,i);
    }
}
